package com.ruoyi.framework.event;


import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.common.error.MicaErrorEvent;
import net.dreamlu.mica.props.MicaProperties;
import net.dreamlu.mica.server.ServerInfo;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

/**
 * MicaErrorEvent 监听
 *
 */
@Slf4j
@AllArgsConstructor
public class RyEventListener {

    private final MicaProperties micaProperties;

    private final ServerInfo serverInfo;

	@Async
	@Order
	@EventListener(MicaErrorEvent.class)
	public void saveErrorLog(MicaErrorEvent event) {
	    event.setAppName(micaProperties.getName());
	    event.setEnv(micaProperties.getEnv());
	    event.setRemoteHost(serverInfo.getHostName());
        log.error(event.toString());
	}

}
